package math.common;

import math.Vector;

public class VectorArithm {
	
	public static Vector sum (Vector v1, Vector v2) {
		int n = v1.getN();
		Double [] s = new Double [n];
		for (int i = 0; i < n; i++) {
			s[i] = v1.get(i) + v2.get(i);
		}
		
		return new Vector(s);
	}
	
	public static Vector diff (Vector v1, Vector v2) {
		return VectorArithm.sum(v1,VectorArithm.comp(v2, -1.0));
	}
	
	public static Vector comp (Vector v1, Double h) {
		int n = v1.getN();
		Double [] c = new Double [n];
		for (int i = 0; i < n; i++) {
			c[i] = v1.get(i) * h;
		}
		
		return new Vector(c);
	}
	
	public static double dist (Vector v1, Vector v2) {
		Vector diff = sum (v1,comp(v2,-1.0));
		double m = Math.abs(diff.get(0));
		for (int i = 1; i < diff.getN(); i++) {
			if (m < Math.abs(diff.get(i))) 
					m = Math.abs(diff.get(i));
		}
		return m;
		
	}
}
